$("#province").on("change",function () {
    var city = $("#province").val();
    $("#area").html("");
    var html = " <option value=''>全部</option>";
    $("#area").append(html);
    getCity(city);
})
$("#city").on("change",function () {
    var city = $("#city").val();
    getArea(city);
})
function getCity(city){
    $.ajax({
        url: '/mutual/city',
        data: {city: city},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#city").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#city").append(html);
        }
    })
}

function getArea(area){
    $.ajax({
        url: '/mutual/area',
        data: {area: area},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#area").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#area").append(html);
        }
    })
}
$(document).ready(function(){
    ajaxList();
});
$(".search").click(function () {
    var data = $("#searchform").serialize();
    var begin_time = $(".begin_time").val();
    var end_time = $(".end_time").val();
    if(begin_time == '' || end_time == ''){
        dshow('请选择需要查询的时间段');
    }else{
        if(begin_time > end_time){
            dshow('结束时间必须大于开始时间');
        }else{
            ajaxList(data);
        }
    }
});

function ajaxList(data) {
    $.ajax({
        url: '/mutual/stylePie',
        data: data,
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            columnPie(data.time,data.data1);
        }
    })
}
function columnPie(data,dataX,dataName) {
    var myChart = echarts.init(document.getElementById('main'));
    option = {
        xAxis: {
            type: 'category',
            data: data
        },
        legend: {
            data:dataName,
            top:10,
            textStyle: {
                fontSize: 14,
                fontWeight: 'bolder',
            }// 主标题文字颜色
        },
        yAxis: {
            type: 'value'
        },
        dataZoom: [
            {
                show: true,
            },
            {
                type: 'inside',
            },
            {
                show: true,
                yAxisIndex: 0,
                filterMode: 'empty',
                width: 30,
                height: '80%',
                showDataShadow: false,
                left: '93%'
            }
        ],
        series:
            dataX,
    };

    myChart.setOption(option);
}

